﻿using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using CrateMayhem.Common.Services;
using CrateMayhem.Common.ViewModel;

namespace CrateMayhem.Desktop.ViewModel
{
    public class AutoCloseDialogViewModel : ViewModelBase
    {
        private string message;

        public AutoCloseDialogViewModel(
            IAutoCloseDialogService autoCloseDialogService, 
            string message, 
            int delayBeforeClose)
        {
            Message = message;
        
            Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(delayBeforeClose);
                    Application.Current.Dispatcher.Invoke(autoCloseDialogService.Close);
                });
        }

        public string Message
        {
            get
            {
                return message;
            }
            set
            {
                message = value; 
                OnPropertyChanged("Message");
            }
        }
    }
}